package com.example.demomultidatasurcejdbk.controller;

import com.example.demomultidatasurcejdbk.entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BookController {
    @Autowired
    protected JdbcTemplate primaryJdbcTemplate;

    @Autowired
    @Qualifier("secondaryJdbcTemplate")
    protected JdbcTemplate secondaryJdbcTemplate;

    @GetMapping("/test1")
    public List<Book> test1(){
        List<Book> books1 = primaryJdbcTemplate.query("select * from book", new BeanPropertyRowMapper<>(Book.class));
        return books1;
    }

    @GetMapping("/test2")
    public List<Book> test2(){
        List<Book> books2 = secondaryJdbcTemplate.query("select * from book", new BeanPropertyRowMapper<>(Book.class));
        return books2;
    }
}
